﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;

namespace CoolCode.Controls
{
    public class CoTabItem : TabItem
    {
        public CoTabItem()
            : base()
        {
            this.DefaultStyleKey = typeof(CoTabItem);
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            ButtonBase close = this.GetTemplateChild("close") as ButtonBase;
            close.Click += new RoutedEventHandler(close_Click);
        }

        void close_Click(object sender, RoutedEventArgs e)
        {
            if (this.OnClose != null)
                OnClose(sender, e);
            var parent = this.Parent as TabControl;
            if (parent != null)
                parent.Items.Remove(this);
        }

        public RoutedEventHandler OnClose { get; set; }
    }
}
